Ruby on Rails - root route in ruby on rails - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
- We can add a home page route to our app with the root method.
# config/routes.rb
Rails.application.routes.draw do
root "application#index"
# equivalent to:
# get "/", "application#index"
end
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
def index
render "homepage"
end
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
And in terminal, rake routes (rails routes in Rails 5) will produce:
root GET / application#index
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
The homepage is usually the most important route, and routes are prioritized in the order they appear, the root route should usually be the first in our routes file.